package cn.school.mybatis.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.school.mybatis.Dao.SubjectDao;
import cn.school.mybatis.join.Subject;
import cn.school.mybatis.xml.MyBatisUtil;

public class SubjectTest {
	public static void main(String[] args) {
		// huoDe();
		add();
	}

	// 修改
	public static void updeta() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		Subject s = new Subject(58, "shuqi", 180, 12);
		int a = subjectDao.update(s);
		System.out.println(a);
		MyBatisUtil.close(session);
	}

	// 删除
	public static void del() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		int b = subjectDao.del(58);
		System.out.println(b);
		MyBatisUtil.close(session);
	}

	// 增加
	public static void add() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		Subject s1 = new Subject("八神烤死", 180, 13);
		int c = subjectDao.add(s1);
		System.out.println(c);
		MyBatisUtil.close(session);
	}

	// 查询单个
	public static void get() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		Subject d = subjectDao.get(1);
		System.out.println(d.toString());
		MyBatisUtil.close(session);
	}

	// 分页查询
	public static void paging() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		List<Subject> list = subjectDao.paging(5, 15);
		for (Subject a : list) {
			System.out.println(a.toString());
		}
		MyBatisUtil.close(session);
	}

	// 连接查询
	public static void huoDe() {
		SqlSession session = MyBatisUtil.get();
		SubjectDao subjectDao = session.getMapper(SubjectDao.class);
		Subject s = subjectDao.huoDe(1);
		System.out.println("该课程的信息为" + s + " 课程所对应的年级名称为:" + s.getGname());
		MyBatisUtil.close(session);
	}
}
